package com.exchange.utils.result;

/***
 *                    .::::.
 *                  .::::::::.
 *                 ::::::::::: 
 *             ..:::::::::::' 
 *           '::::::::::::'
 *             .::::::::::
 *        '::::::::::::::..
 *             ..::::::::::::.
 *           ``::::::::::::::::
 *            ::::``:::::::::'        .:::.
 *           ::::'   ':::::'       .::::::::.
 *         .::::'      ::::     .:::::::'::::.
 *        .:::'       :::::  .:::::::::' ':::::.
 *       .::'        :::::.:::::::::'      ':::::.
 *      .::'         ::::::::::::::'         ``::::.
 *  ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 *                    '.:::::'                    ':'````..
 *
 * @Author liuhai
 * @Date 2020-10-04 11:33:45
 * @Description 公共返回的数据结构
 */
public class CommonResult {

    // 返回代码
    private String code;
    // 提示信息
    private String message;
    // 返回数据
    private Object data;

    public CommonResult(){}

    public CommonResult(String code){
        this.code = code;
    }

    public CommonResult(String code, String message){
        this.code = code;
        this.message = message;
    }

    public CommonResult(String code, String message, Object data){
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 成功
     * @param message
     * @return
     */
    public static CommonResult success(String message){
        return new CommonResult(ResultCodeEnum.SUCCESS.getCode(), message);
    }

    /**
     * 成功，返回数据
     * @param message
     * @param data
     * @return
     */
    public static CommonResult successWithData(String message, Object data){
        return new CommonResult(ResultCodeEnum.SUCCESS.getCode(), message, data);
    }

    /**
     * 失败
     * @param message
     * @return
     */
    public static CommonResult fail(String message){
        return new CommonResult(ResultCodeEnum.FAIL.getCode(), message);
    }

    /**
     * 异常
     * @param message
     * @return
     */
    public static CommonResult error(String message){
        return new CommonResult(ResultCodeEnum.ERROR.getCode(), message);
    }

    /**
     * 异常，返回异常信息
     * @param message
     * @param info
     * @return
     */
    public static CommonResult errorWithInfo(String message, Object info){
        return new CommonResult(ResultCodeEnum.ERROR.getCode(), message, info);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
